from selenium.webdriver.common.by import By

from Common.Utils import BlogDriver

from time import sleep

class Register:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

        # 注册页面跳转并注册

    def RegistrationPage(self):
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        BlogDriver.getScreenshort()

        # 已有账号的跳转
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div > div.text-center.text-muted.mt-3 > a").click()
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.back()

        # 注册账号
        # 全部为空,直接注册
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()

        # 输入用户名
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()

        # 输入昵称
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("小小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()

        # 输入密码
        password_field = self.driver.find_element(By.CSS_SELECTOR, "#password")
        password_field.send_keys("123456")
        self.driver.execute_script("arguments[0].type='text';", password_field)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.execute_script("arguments[0].type='password';", password_field)
        sleep(1)
        BlogDriver.getScreenshort()

        # 再次输入密码
        password_repeat = self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat")
        password_repeat.send_keys("123456")
        self.driver.execute_script("arguments[0].type='text';", password_repeat)
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreenshort()
        self.driver.execute_script("arguments[0].type='password';", password_repeat)
        sleep(1)
        BlogDriver.getScreenshort()
        # 同意协议并提交
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        sleep(1)
        BlogDriver.getScreenshort()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        sleep(1)
        self.driver.execute_script("arguments[0].type='password';", password_field)
        BlogDriver.getScreenshort()


    #用户信息再注册

    def RegistrationRepeat(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("小ming")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("小小ming")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        BlogDriver.getScreenshort()








